home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
198_01
/
bind.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-01-21
|
19KB
|
807 lines
/* This file is for functions having to do with key bindings,
descriptions, help commands and startup file.
written 11-feb-86 by Daniel Lawrence
*/
#include <stdio.h>
#include "estruct.h"
#include "edef.h"
#include "epath.h"
extern int meta(), cex(), unarg(), ctrlg(); /* dummy prefix binding functions */
help(f, n) /* give me some help!!!!
bring up a fake buffer and read the help file
into it with view mode */
{
register BUFFER *bp; /* buffer pointer to help */
char *fname; /* ptr to file returned by flook() */
/* first check if we are already here */
bp = bfind("emacs.hlp", FALSE, BFINVS);
if (bp == NULL) {
fname = flook(pathname[1], FALSE);
if (fname == NULL) {
mlwrite("[Help file is not online]");
return(FALSE);
}
}
/* split the current window to make room for the help stuff */
if (splitwind(FALSE, 1) == FALSE)
return(FALSE);
curwp = spltwp; curbp = curwp->w_bufp;
if (bp == NULL) {
/* and read the stuff in */
if (getfile(fname, FALSE) == FALSE)
return(FALSE);
} else
swbuffer(bp);
/* make this window in VIEW mode, update all mode lines */
curbp->b_mode |= MDVIEW;
curbp->b_flag |= BFINVS;
upmode();
return(TRUE);
}
deskey(f, n) /* describe the command for a certain key */
{
register int c; /* key to describe */
register char *ptr; /* string pointer to scan output strings */
char outseq[NSTRING]; /* output buffer for command sequence */
#if C86 | DECUSC
int *getbind();
#else
int (*getbind())();
#endif
/* prompt the user to type us a key to describe */
mlwrite(": describe-key ");
/* get the command sequence to describe
change it to something we can print as well */
cmdstr(c = getckey(FALSE), &outseq[0]);
/* and dump it out */
ostring(outseq);
ostring(" ");
/* find the right ->function */
if ((ptr = getfname(getbind(c))) == NULL)
ptr = "Not Bound";
/* output the command sequence */
ostring(ptr);
}
/* bindtokey: add a new key to the key binding table */
bindtokey(f, n)
int f, n; /* command arguments [IGNORED] */
{
register unsigned int c;/* command key to bind */
register (*kfunc)(); /* ptr to the requested function to bind to */
register KEYTAB *ktp; /* pointer into the command table */
register int found; /* matched command flag */
char outseq[80]; /* output buffer for keystroke sequence */
int (*getname())();
#if C86 | DECUSC
int (*fmeta)(), (*fcex)(), (*funarg)(), (*fctrlg)();
fmeta = meta; fcex = cex; funarg = unarg; fctrlg = ctrlg;
#else
#define fmeta meta
#define fcex cex
#define funarg unarg
#define fctrlg ctrlg
#endif
/* prompt the user to type in a key to bind */
mlwrite(": bind-to-key ");
/* get the function name to bind it to */
kfunc = getname();
if (kfunc == NULL) {
mlwrite("[No such function]");
return(FALSE);
}
ostring(" ");
/* get the command sequence to bind */
TTflush();
c = getckey((kfunc == fmeta) || (kfunc == fcex) ||
(kfunc == funarg) || (kfunc == fctrlg));
/* change it to something we can print as well */
cmdstr((int) c, &outseq[0]);
/* and dump it out */
ostring(outseq);
/* if the function is a prefix key */
if (kfunc == fmeta || kfunc == fcex ||
kfunc == funarg || kfunc == fctrlg) {
/* search for an existing binding for the prefix key */
ktp = &keytab[0];
#if DECEDT
if (kfunc == funarg || kfunc == fctrlg)
#endif
while (ktp->k_fp != NULL) {
if (ktp->k_fp == kfunc)
chunbind(ktp->k_code);
++ktp;
}
/* reset the appropriate global prefix variable */
if (kfunc == fmeta) metac = c;
if (kfunc == fcex) ctlxc = c;
if (kfunc == funarg) reptc = c;
if (kfunc == fctrlg) abortc = c;
}
/* search the table to see if it exists */
ktp = &keytab[0];
found = FALSE;
while (ktp->k_fp != NULL) {
if (ktp->k_code == c) {
found = TRUE;
break;
}
++ktp;
}
if (found) { /* it exists, just change it then */
if (ktp->k_fp == fmeta) metac = 0;
if (ktp->k_fp == fcex) ctlxc = 0;
if (ktp->k_fp == funarg) reptc = 0;
if (ktp->k_fp == fctrlg) abortc = 0;
ktp->k_fp = kfunc;
if (c > 0 && c < NFBIND) fkeytab[c] = kfunc;
else if (c == (FUNC|'C')) ffuncc = kfunc;
fkeylast.k_code = c;
fkeylast.k_fp = kfunc;
} else { /* otherwise we need to add it to the end */
/* if we run out of binding room, bitch */
if (ktp >= &keytab[NBINDS]) {
mlwrite("Binding table FULL!");
return(FALSE);
}
ktp->k_code = c; /* add keycode */
ktp->k_fp = kfunc; /* and the function pointer */
++ktp; /* and make sure the next is null */
ktp->k_code = 0;
ktp->k_fp = NULL;
if (c > 0 && c < NFBIND) fkeytab[c] = kfunc;
else if (c == (FUNC|'C')) ffuncc = kfunc;
fkeylast.k_code = c;
fkeylast.k_fp = kfunc;
}
return(TRUE);
}
/* unbindkey: delete a key from the key binding table */
unbindkey(f, n)
int f, n; /* command arguments [IGNORED] */
{
register int c; /* command key to unbind */
char outseq[80]; /* output buffer for keystroke sequence */
/* prompt the user to type in a key to unbind */
mlwrite(": unbind-key ");
/* get the command sequence to unbind */
c = getckey(FALSE); /* get a command sequence */
/* change it to something we can print as well */
cmdstr(c, &outseq[0]);
/* and dump it out */
ostring(outseq);
/* if it isn't bound, bitch */
if (chunbind(c) == FALSE) {
mlwrite("[Key not bound]");
return(FALSE);
}
return(TRUE);
}
chunbind(c)
int c; /* command key to unbind */
{
register KEYTAB *ktp; /* pointer into the command table */
register KEYTAB *sktp; /* saved pointer into the command table */
register int found; /* matched command flag */
/* search the table to see if the key exists */
ktp = &keytab[0];
found = FALSE;
while (ktp->k_fp != NULL) {
if (ktp->k_code == c) {
found = TRUE;
break;
}
++ktp;
}
/* if it isn't bound, bitch */
if (!found)
return(FALSE);
/* save the pointer and scan to the end of the table */
sktp = ktp;
while (ktp->k_fp != NULL)
++ktp;
--ktp; /* backup to the last legit entry */
/* copy the last entry to the current one */
sktp->k_code = ktp->k_code;
sktp->k_fp = ktp->k_fp;
/* null out the last one */
ktp->k_code = 0;
ktp->k_fp = NULL;
/* clear in fast lookup area */
if (c > 0 && c < NFBIND) fkeytab[c] = NULL;
else if (c == (FUNC|'C')) ffuncc = NULL;
fkeylast.k_code = keytab[0].k_code;
fkeylast.k_fp = keytab[0].k_fp;
return(TRUE);
}
desbind(f, n) /* describe bindings
bring up a fake buffer and list the key bindings
into it with view mode */
#if APROP
{
buildlist(TRUE, "");
}
apro(f, n) /* Apropos (List functions that match a substring) */
{
char mstring[NSTRING]; /* string to match cmd names to */
int status; /* status return */
status = mlreply("Apropos string: ", mstring, NSTRING - 1);
if (status != TRUE)
return(status);
return(buildlist(FALSE, mstring));
}
buildlist(type, mstring) /* build a binding list (limited or full) */
int type; /* true = full list, false = partial list */
char *mstring; /* match string if a partial list */
#endif
{
#if ST520 & LATTICE
#define register
#endif
register WINDOW *wp; /* scanning pointer to windows */
register KEYTAB *ktp; /* pointer into the command table */
register NBIND *nptr; /* pointer into the name binding table */
register BUFFER *bp; /* buffer to put binding list into */
int cpos; /* current position to use in outseq */
char outseq[80]; /* output buffer for keystroke sequence */
/* split the current window to make room for the binding list */
if (splitwind(FALSE, 1) == FALSE)
return(FALSE);
curwp = spltwp; curbp = curwp->w_bufp;
/* and get a buffer for it */
bp = bfind("Binding list", TRUE, 0);
if (bp == NULL || bclear(bp) == FALSE) {
mlwrite("Can not display binding list");
return(FALSE);
}
/* let us know this is in progress */
mlwrite("[Building binding list]");
/* disconect the current buffer *